// pages/index/search/search.js
Page({
  /**
   * 页面的初始数据
   */
  data: {},
  onSearch: function (event) {
    var search = event.detail.value;
    this.setData({
      'search': ''
    });

    if (search) {
      var history = my.getStorageSync({key: 'history'})['data'];

      if (!history) {
        history = new Array();
        history.push(search);
        my.setStorageSync({key: 'history', data: history});
      } else {
        if (history.length < 11) {
          history.unshift(search);
        } else {
          history.pop();
          history.unshift(search);
        }

        my.setStorageSync({key: 'history', data: history});
      }

      my.navigateTo({
        url: '/pages/list/list?search=' + search
      });
    } else {
      my.showToast({
        content: '请输入搜索内容'
      });
    }
  },
  onLabelSearch: function (event) {
    var search = event.currentTarget.dataset.value;
    this.setData({
      'search': ''
    });

    if (search) {
      my.navigateTo({
        url: '/pages/list/list?search=' + search
      });
    } else {
      my.showToast({
        content: '请输入搜索内容'
      });
    }
  },
  onBack: function () {
    my.navigateBack();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var history = my.getStorageSync({key: 'history'})['data'];
    this.setData({
      'history': history
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var history = my.getStorageSync({key: 'history'})['data'];

    if (!history) {
      history = new Array();
      my.setStorageSync({key: 'history', data: history});
    }

    this.setData({
      'history': history
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  enterNcov: function(){
    my.navigateToMiniProgram({
      appId: '2021001132600368',
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
});